/**
 * @description: 文件描述
 * @version: 0.0.1
 * @author: xxx
 * @Date: 2025-03-04 11:25:29
 */

// 统一的URL验证函数
const validateHttpsUrl = (value, fieldName) => {
    const imageUrlPattern = /^https:\/\/.*/;
    if (!value) {
        return `请输入${fieldName}`;
    } else if (!imageUrlPattern.test(value)) {
        return `请输入有效的${fieldName}`;
    }
    return '';
};

export const createUrlValidator = (fieldName) => (rule, value, callback) => {
    const error = validateHttpsUrl(value, fieldName);
    if (error) {
        callback(new Error(error));
    } else {
        callback();
    }
};

export const validatorVideoTitle = (fieldName, length = 20) => (rule, value, callback) => {
    if (!value) {
        callback(new Error(`请输入${fieldName}`));
    } else if (value.length > length) {
        callback(new Error(`${fieldName}不能超过${length}个字符`));
    } else {
        callback();
    }
}; 